package com.macrounion.atv.config;
import org.springframework.util.StringUtils;
import org.springframework.web.servlet.LocaleResolver;
 
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.Locale;
 
public class SwitchLocalResolver implements LocaleResolver{
 
    @Override
    public Locale resolveLocale(HttpServletRequest request) {
        String lang = request.getParameter("_lang");
        if(StringUtils.isEmpty(lang))
        	lang = request.getHeader("_lang");
        if(StringUtils.isEmpty(lang))
        	lang = request.getHeader("lang");
//        System.out.println("语言：---》"+lang);
        Locale locale = Locale.getDefault();
        if (!StringUtils.isEmpty(lang)) {
            String[] split = lang.split("_");
            locale = new Locale(split[0],split[1]);
 
        }
        return locale;
    }
 
    @Override
    public void setLocale(HttpServletRequest request, HttpServletResponse response, Locale locale) {
 
    }
}
